cmake_minimum_required(VERSION 3.10)
project(OSG_Projects)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 定义OSG相关路径变量，允许在CMake GUI中设置
set(OSG_INCLUDE_DIR "" CACHE PATH "OSG库的头文件目录")
set(OSG_LIB_DIR_DEBUG "" CACHE PATH "OSG库DEBUG模式静态库目录")
set(OSG_LIB_DIR_RELEASE "" CACHE PATH "OSG库RELEASE模式静态库目录")

# 检查必要路径
if(NOT OSG_INCLUDE_DIR)
    message(FATAL_ERROR "请在CMake GUI中设置OSG_INCLUDE_DIR路径")
endif()

if(NOT OSG_LIB_DIR_DEBUG)
    message(FATAL_ERROR "请在CMake GUI中设置OSG_LIB_DIR_DEBUG路径")
endif()

if(NOT OSG_LIB_DIR_RELEASE)
    message(FATAL_ERROR "请在CMake GUI中设置OSG_LIB_DIR_RELEASE路径")
endif()

# 把每个项目的所有文件按照文件夹结构加到IDE里
function(create_file_structure source_list header_list)
    foreach(source IN LISTS ${source_list} ${header_list})
        file(RELATIVE_PATH relPath ${CMAKE_CURRENT_SOURCE_DIR} ${source})
        get_filename_component(groupPath "${relPath}" DIRECTORY)
        if(NOT "${groupPath}" STREQUAL "")
            source_group(${groupPath} FILES ${source})
        endif()
    endforeach()
endfunction()   

# 添加当前项目到IDE的指定文件夹中
function(add_project_to_folder project_name folder_name)
    set_target_properties(${project_name} PROPERTIES
        FOLDER ${folder_name}  # 指定解决方案文件夹
    )
endfunction()

# 获取源文件列表
function(get_source_list ret_list)
    file(GLOB_RECURSE SRCS "*.cpp")
    set(${ret_list} ${SRCS} PARENT_SCOPE)
endfunction()

# 获取头文件列表
function(get_header_list ret_list)
    file(GLOB_RECURSE  HEADERS "*.h")
    set(${ret_list} ${HEADERS} PARENT_SCOPE)
endfunction()


# 添加子项目
add_subdirectory(Common)

add_subdirectory(part1)
add_subdirectory(part2)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)


